import {Toast} from "@taroify/core";
import {useEffect, useState} from "react";
import type {ToastType} from "@taroify/core/toast/toast.shared";

export default function GlobalToast(props: { type: ToastType, message: string }) {

  const [message, setMessage] = useState<string>("加载中...");
  const [type, setType] = useState<ToastType>("loading");

  useEffect(() => {
    if (props?.type) {
      setType(props.type)
    }

    if (props?.message) {
      setMessage(props.message)
    }
  }, []);

  return (
    <Toast open type={type}>
      {message}
    </Toast>
  )
}
